package com.example.x3day04.activity;

import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.ContextMenu;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.x3day04.R;
import com.example.x3day04.base.BaseActivity;
import com.example.x3day04.bean.Bean;
import com.example.x3day04.presenter.MainPresenter;
import com.example.x3day04.ui.adapter.RlvAdapter;
import com.example.x3day04.view.MainView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity<MainPresenter> implements MainView {

    @BindView(R.id.rlv)
    RecyclerView mRlv;
    /**
     * 爱上对方过后就哭了
     */
    private TextView mTv;
    private ArrayList<Bean.ResultsBean> list;
    private RlvAdapter rlvAdapter;


    @Override
    protected MainPresenter getPresenter() {
        return new MainPresenter();
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getData();
    }

    @Override
    protected void initView() {
        mRlv.setLayoutManager(new LinearLayoutManager(this));
        mRlv.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL));
        list = new ArrayList<>();
        rlvAdapter = new RlvAdapter(this, list);
        mRlv.setAdapter(rlvAdapter);

    }

    @Override
    protected int getLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void getData(Bean bean) {
        List<Bean.ResultsBean> results = bean.getResults();
        this.list.addAll(results);
        rlvAdapter.notifyDataSetChanged();
        Log.i("111", "getData: ");
    }

    @Override
    public void showToast(String str) {
        Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
    }
}